# 感知机实现 与门、与非门、或门


import  numpy as np



# 与门

# def AND(x1,x2):
#     w1,w2,theat=0.5,0.5,0.7
#     tmp = w1*x1 + w2*x2
#     if tmp > theat:
#         return True
#     else:
#         return False
#
# print(AND(0,0))
# print(AND(0,1))
# print(AND(1,0))
# print(AND(1,1))


def AND(x1,x2):
    x = np.array([x1,x2])
    w = np.array([0.5,0.5])
    b=-0.7
    tmp = np.sum(x*w)+ b
    if tmp > 0:
        return True
    else:
        return False
#
# print(AND(0,0))
# print(AND(0,1))
# print(AND(1,0))
# print(AND(1,1))


# 与非门

# def NAND(x1,x2):
#     w1,w2,theat=0.5,0.5,0.7
#     tmp = w1*x1 + w2*x2
#     if tmp > theat:
#         return False
#     else:
#         return True
#
# print(NAND(0,0))
# print(NAND(0,1))
# print(NAND(1,0))
# print(NAND(1,1))

def NAND(x1,x2):
    x = np.array([x1,x2])
    w = np.array([0.5,0.5])
    b=-0.7
    tmp = np.sum(x*w)+ b
    if tmp > 0:
        return False
    else:
        return True
#
# print(NAND(0,0))
# print(NAND(0,1))
# print(NAND(1,0))
# print(NAND(1,1))

# 或门

# def OR(x1,x2):
#     w1,w2,theat=1.0,1.0,0.7
#     tmp = w1*x1 + w2*x2
#     if tmp > theat:
#         return True
#     else:
#         return False
#
# print(OR(0,0))
# print(OR(0,1))
# print(OR(1,0))
# print(OR(1,1))

def OR(x1,x2):
    x = np.array([x1,x2])
    w = np.array([1.0,1.0])
    b=-1.0
    tmp = np.sum(x*w)+ b
    if tmp >= 0:
        return True
    else:
        return False
#
# print(OR(0,0))
# print(OR(0,1))
# print(OR(1,0))
# print(OR(1,1))


#异或门

def XOR(x1,x2):
    s1=NAND(x1,x2)
    s2=OR(x1,x2)
    y=AND(s1,s2)
    return y

print(XOR(0,0))
print(XOR(0,1))
print(XOR(1,0))
print(XOR(1,1))